# sql    这里的引擎位置这样：是由于导入后路径会改变相对位置，mysql不用此注意。
from sqlalchemy import create_engine
from config.app_static_ import DB_URL, POOL_SIZE,MAX_OVERFLOW,POOL_RECYCLE,POOL_TIMEOUT,POOL_PRE_PING
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import declarative_base
engine = create_engine(DB_URL,pool_size=POOL_SIZE,
                            max_overflow=MAX_OVERFLOW,
                            pool_pre_ping=POOL_PRE_PING,
                            pool_timeout=POOL_TIMEOUT,
                            pool_recycle=POOL_RECYCLE)
SessionLocal = sessionmaker(autocommit=False, autoflush=True,
                            bind=engine
                            )
Base = declarative_base()


#用于返回session
# 由于架构都采用的return db,不再使用yield自动管理
def get_db():
     db = SessionLocal()
     try:
         return db
     except Exception as e:
         db.close()
         print(e)



